package com.exam.project.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.exam.framework.aspectj.lang.annotation.Log;
import com.exam.framework.aspectj.lang.enums.BusinessType;
import com.exam.project.business.domain.UserAnswer;
import com.exam.project.business.service.IUserAnswerService;
import com.exam.framework.web.controller.BaseController;
import com.exam.framework.web.domain.AjaxResult;
import com.exam.common.utils.poi.ExcelUtil;
import com.exam.framework.web.page.TableDataInfo;

/**
 * 答案Controller
 * 
 * @author qiuwenbing
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/business/useranswer")
public class UserAnswerController extends BaseController
{
    @Autowired
    private IUserAnswerService userAnswerService;

    /**
     * 查询答案列表
     */
    @PreAuthorize("@ss.hasPermi('business:useranswer:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserAnswer userAnswer)
    {
        startPage();
        List<UserAnswer> list = userAnswerService.selectUserAnswerList(userAnswer);
        return getDataTable(list);
    }

    /**
     * 导出答案列表
     */
    @PreAuthorize("@ss.hasPermi('business:useranswer:export')")
    @Log(title = "答案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserAnswer userAnswer)
    {
        List<UserAnswer> list = userAnswerService.selectUserAnswerList(userAnswer);
        ExcelUtil<UserAnswer> util = new ExcelUtil<UserAnswer>(UserAnswer.class);
        util.exportExcel(response, list, "答案数据");
    }

    /**
     * 获取答案详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:useranswer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userAnswerService.selectUserAnswerById(id));
    }

    /**
     * 新增答案
     */
    @PreAuthorize("@ss.hasPermi('business:useranswer:add')")
    @Log(title = "答案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserAnswer userAnswer)
    {
        return toAjax(userAnswerService.insertUserAnswer(userAnswer));
    }

    /**
     * 修改答案
     */
    @PreAuthorize("@ss.hasPermi('business:useranswer:edit')")
    @Log(title = "答案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserAnswer userAnswer)
    {
        return toAjax(userAnswerService.updateUserAnswer(userAnswer));
    }

    /**
     * 删除答案
     */
    @PreAuthorize("@ss.hasPermi('business:useranswer:remove')")
    @Log(title = "答案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userAnswerService.deleteUserAnswerByIds(ids));
    }
}
